package com.jyou.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.jyou.stock.Price;

@Controller
@RequestMapping("/allPrice")
public class StockController {
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView doAllPrice(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		try{
			JSONArray ja = new JSONArray();
			String param = request.getParameter("data");
			String[] tickers = param.split(";");
			for(int i = 0; i < tickers.length; i++){
				JSONObject jo = Price.getResultByTicker(tickers[i]);
				ja.add(jo);
			}
			response.getWriter().write(ja.toString());
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
}
